/**
 * Create by CaoWenjian
 *
 * @copyRight: 2018
 **/
package com.bjboot.caocao.system.controller;

import com.bjboot.caocao.common.utils.Query;
import com.bjboot.caocao.common.utils.Result;
import com.bjboot.caocao.system.domain.LogDO;
import com.bjboot.caocao.system.domain.PageDO;
import com.bjboot.caocao.system.service.LogService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 *@Description 登陆日志查询控制器
 *@Author 操文健
 *@Date 2018-09-19 下午2:49
 *@Version 1.0
 **/
@RequestMapping("/sys/log")
@Controller
public class LogController {

    @Autowired
    LogService logService;
    String prefix = "system/log";

    @ApiOperation(value = "获取日志界面Module")
    @GetMapping()
    String log() {
        return prefix + "/log";
    }

    @ApiOperation(value = "分页查询日志列表")
    @ResponseBody
    @GetMapping("/list")
    PageDO<LogDO> list(@RequestParam Map<String, Object> params) {
        Query query = new Query(params);
        PageDO<LogDO> page = logService.queryList(query);
        return page;
    }

    @ApiOperation(value = "删除日志")
    @ResponseBody
    @PostMapping("/remove")
    Result remove(Long id) {
        if (logService.remove(id)>0) {
            return Result.ok();
        }
        return Result.error();
    }

    @ApiOperation(value = "批量删除日志")
    @ResponseBody
    @PostMapping("/batchRemove")
    Result batchRemove(@RequestParam("ids[]") Long[] ids) {
        int r = logService.batchRemove(ids);
        if (r > 0) {
            return Result.ok();
        }
        return Result.error();
    }
}
